<template>
  <div class="app-page">
    <el-table-form ref="form" :model="query">
      <el-form-item label="统计日期:" :table-form-merge="2">
        <el-date-picker
          v-model="date"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :clearable="false"
        />
      </el-form-item>
      <el-form-item>
        <el-select v-model="query.configType">
          <el-option label="催单配置:" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="账号名称:" prop="searchKeywords">
        <el-input v-model.trim="query.searchKeywords" placeholder="请输入" clearable />
      </el-form-item>
      <template v-slot:btns>
        <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
      </template>
    </el-table-form>
    <lb-table
      ref="lbTable"
      v-el-height-adaptive-table="{bottomOffset:10}"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      :data="tableData.data"
      pagination
      :total="tableData.total"
      :wrap="true"
      custom-column
      @fetch="fetchData"
    />
  </div>
</template>

<script>
  import { querySystemHandleList } from '@/api'
  import { parseTime } from '@/utils'
  import moment from 'dayjs'

  export default {
    name: 'systemHandleLog',
    data() {
      return {
        date: [moment().startOf('day'), moment().endOf('day')],
        query: {
          configType: 3,
          searchKeywords: ''
        },
        tableData: {
          total: 0,
          column: [
            {
              type: 'index'
            },
            {
              prop: 'createTime',
              width: 150,
              label: '操作时间',
              render: (h, { row }) => <span>{ row.createTime && parseTime(row.createTime, '{y}-{m}-{d} {h}:{i}') }</span>
            },
            {
              prop: 'configTypeName',
              width: 100,
              label: '功能'
            },
            {
              prop: 'changeDescription',
              label: '操作内容'
            },
            {
              prop: 'operatorCode',
              width: 60,
              label: '账号'
            },
            {
              prop: 'operatorName',
              width: 100,
              label: '账号名称'
            },
            {
              prop: 'ipAddress',
              label: 'IP地址',
              width: 150
            }
          ],
          data: []
        }
      }
    },
    methods: {
      _getQuery(obj) {
        const query = {}
        for (const key in obj) {
          if (obj.hasOwnProperty(key)) {
            if (obj[key] !== '') {
              query[key] = obj[key]
            }
          }
        }
        return query
      },
      async fetchData({ currentPage, pageSize }) {
        const query = {
          ...this._getQuery(this.query),
          currentPage,
          pageSize
        }
        if (this.date && this.date.length > 0) {
          query.startDate = moment(this.date[0]).format()
          query.endDate = moment(this.date[1]).format()
        }
        const res = await querySystemHandleList(query)
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
      },
      search() {
        this.$refs.lbTable.fetch({ currentPage: 1 })
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
